package com.wc.算法提高课.B第二章_搜索.DFS之剪枝与优化.木棒;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/29 14:08
 * @description https://www.acwing.com/problem/content/description/169/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 70;
    static int[] w = new int[N];
    static boolean[] st = new boolean[N];
    static int sum = 0, length = 0;
    static int n;

    public static void main(String[] args) {
        while (true) {
            n = sc.nextInt();
            sum = length = 0;
            if (n == 0) break;
            for (int i = 0; i < n; i++) {
                w[i] = sc.nextInt();
                st[i] = false;
                sum += w[i];
                length = Math.max(length, w[i]);
            }
            Arrays.sort(w, 0, n);
            for (int i = 0, j = n - 1; i < j; i++, j--) {
                int tmp = w[i];
                w[i] = w[j];
                w[j] = tmp;
            }
            while (true) {
                if (sum % length == 0 && dfs(0, 0, 0)) {
                    out.println(length);
                    break;
                }
                length++;
            }
        }
        out.flush();
    }

    static boolean dfs(int u, int s, int start) {
        if (u * length == sum) return true;
        if (s == length) return dfs(u + 1, 0, 0);

        for (int i = start; i < n; i++) {
            if (st[i]) continue;
            if (s + w[i] > length) continue;
            st[i] = true;
            if (dfs(u, s + w[i], i + 1)) return true;
            st[i] = false;
            if (s == 0) return false;
            if (s + w[i] == length) return false;
            int j = i;
            // 去除重复判断的, 不满足的
            while (j < n && w[j] == w[i]){
                j++;
            }
            i = j - 1;
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
